<?php
class UsersController extends AppController {

    var $name = 'Users';

    /**
     *  The AuthComponent provides the needed functionality
     *  for login, so you can leave this function blank.
     */
    function login() {
        if(isset($this->data['User'])){
			$user=$this->User->findByUsername($this->data['User']['username']);
			if(empty($user))
			    $this->Session->setFlash("Invalid Username or Password");
			elseif($user['User']['password']!=$this->data['User']['password'])
	            $this->Session->setFlash("Invalid Username or Password");
			else{
			    $this->Session->write("userid",$user['User']['id']);
			    $this->redirect("/journeys/jlist");
			}
        }
    }
    
    function signup() {
        if(isset($this->data['User'])){
            $this->User->create();
            $this->User->save($this->data);
            $this->Session->setFlash("User has been successfully created.");
            $this->redirect("/");
        }
	}

    function logout() {
        $this->Session->destroy();
    }
}


?>
